package com.csaba.swing.gui.dummy;

import javax.swing.JComboBox;
import javax.swing.JLabel;

import com.csaba.connector.dummy.model.DummyBank;
import com.csaba.connector.model.Customer;
import com.csaba.swing.gui.login.AbstractLoginPage;
import com.csaba.swing.gui.login.LoginDetails;
import com.csaba.swing.gui.wizard.WizardContext;
import com.csaba.util.I18N;

@SuppressWarnings( "serial" )
public class DummyLoginPage extends AbstractLoginPage
{
	private final static String[] CUSTOMERS = new String[] { "local", "foreign", "error1", "loginError" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$

	private JComboBox customerCombo;

	@Override
	public void init( final WizardContext context )
	{
		super.init(context);

		add(new JLabel(I18N.getString(this, "DummyLoginPage.customer"))); //$NON-NLS-1$
		add(customerCombo = new JComboBox(CUSTOMERS));
	}

	@Override
	public boolean leave( final int action )
	{
		if ( action == ACTION_FINISH )
		{
			final Customer customer = new Customer();
			customer.setLoginId((String) customerCombo.getSelectedItem());
			customer.setPassword("password"); //$NON-NLS-1$
			customer.setBank(DummyBank.getInstance());
			return doLogin(customer);
		}
		return true;
	}

	@Override
	public void updateView()
	{
		context.getDialog().setReady(true);

	}

	@Override
	protected LoginDetails getDetailsToSave( final Customer customer )
	{
		// there is nothing to save
		return null;
	}

	@Override
	protected void setSavedDetails( final LoginDetails details )
	{
		// there is nothing to load		
	}

}
